<?php

class FileUploadHandler{
	
	// Kontrollerar filtypen
	public function CheckFile($File)
	{
		$AllowedExtensions = array("jpg", "jpeg", "gif", "png", "pdf");
		
		$FileExtension = explode(".", $File["name"]);

		$FileExtension = end($FileExtension);

		if($File["type"] == "image/png" 
			|| $File["type"] == "image/gif"
			|| $File["type"] == "image/jpeg"
			|| $File["type"] == "image/pjpeg"
			|| $File["type"] == "application/pdf"
			&& in_array($FileExtension, $AllowedExtensions) == true){
				if($File["error"] > 0){
					return false;
				}
				else if(file_exists("uploadedFiles/" . $File["name"])){
					echo "Filnamnet finns redan";
					return false;
				}
				else{
					return true;	
				}				
		}
		else{
			return false;
		}
		
	}

	// Funktion som sparar en uppladdad fil
	public function SaveFile($File)
	{
		move_uploaded_file($File["tmp_name"], "uploadedFiles/" . $File["name"]);
		return true;
	}
}